<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>平时成绩管理系统-规则管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
</head>
<body>

<div class="layui-form" lay-filter="layuiadmin-form-useradmin" id="layuiadmin-form-rule"
     style="padding: 20px 0 0 0;">
    <div class="layui-form-item">
        <label class="layui-form-label">课程</label>
        <div class="layui-input-inline">
            <select name="courseId" id="courseId"></select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">教师</label>
        <div class="layui-input-inline">
            <select name="teacherId" lay-search="" id="teacherId"></select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">考勤占比</label>
        <div class="layui-input-block">
            <input type="number" step="0.01" name="ruleAttendance" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">作业占比</label>
        <div class="layui-input-block">
            <input type="number" step="0.01" name="ruleHomework" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">上课占比</label>
        <div class="layui-input-block">
            <input type="number" step="0.01" name="ruleClazz" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">期中占比</label>
        <div class="layui-input-block">
            <input type="number" step="0.01" name="ruleMiddle" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">期末占比</label>
        <div class="layui-input-block">
            <input type="number" step="0.01" name="ruleEnd" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="LAY-form-rule-submit" id="LAY-form-rule-submit" value="确认">
    </div>
</div>

<script src="../../layuiadmin/layui/layui.js"></script>
<!--课程option选项模板-->
<script id="optionCourse" type="text/html">
    <option value="">全部</option>
    {{#  layui.each(d.data, function(index, rule){  }}
    <option value="{{rule.courseId}}">
        {{rule.courseId}}： {{rule.courseName}}
    </option>
    {{#  }); }}
    {{#  if(d.data.length === 0){ }}
    无数据
    {{#  } }}
</script>
<!--教师option选项模板-->
<script id="optionTeacherId" type="text/html">
    {{#  layui.each(d.data, function(index, teacher){  }}
    <option value="{{teacher.teacherId}}">
        {{teacher.teacherId}}: {{teacher.teacherName}}
    </option>
    {{#  }); }}
    {{#  if(d.data.length === 0){ }}
    无数据
    {{#  } }}
</script>
<script>
    layui.config({
        base: '../../layuiadmin/'
    }).extend({
        index: 'lib/index'
    }).use(['index', 'form', 'laytpl'], function () {
        let $ = layui.$
            , setter = layui.setter
            , laytpl = layui.laytpl
            , form = layui.form;

        /*
            加载课程信息
        */
        $(function () {
            $.ajax({
                url: setter.baseUrl + '/teacher/ins',
                dataType: "json",
                type: "get",
                contentType: 'application/json',
                xhrFields: {
                    withCredentials: true
                },
                success: function (res) {
                    if (res.code === 200) {
                        let getTpl = optionTeacherId.innerHTML
                            , view = document.getElementById('teacherId');
                        laytpl(getTpl).render(res, function (html) {
                            view.innerHTML = html;
                        });
                        form.render(); //更新全部
                    } else {
                        layer.msg("失败");
                    }

                },
                error: function (e) {
                    layer.msg("失败");
                }
            });
            $.ajax({
                url: setter.baseUrl + '/course/ins',
                dataType: "json",
                type: "get",
                contentType: 'application/json',
                xhrFields: {
                    withCredentials: true
                },
                success: function (res) {
                    if (res.code === 200) {
                        let getTpl = optionCourse.innerHTML
                            , view = document.getElementById('courseId');
                        laytpl(getTpl).render(res, function (html) {
                            view.innerHTML = html;
                        });
                        form.render(); //更新全部
                    } else {
                        layer.msg("失败");
                    }

                },
                error: function (e) {
                    layer.msg("失败");
                }
            });
        });
    })
</script>
</body>
</html>
